package com.yyf.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitTopicConfig {
    //队列1:处理支付业务
    @Bean
    public Queue payQueue() {
        return new Queue("pay.topic.queue", true);
    }

    //队列2：处理日志
    @Bean
    public Queue payLogQueue() {
        return new Queue("pay.log.topic.queue", true);
    }

    //topic交换机
    @Bean
    public TopicExchange payTopicExchange() {
        return new TopicExchange("pay.topic.exchange", true, false);
    }

    //绑定1路由建以”pay.“开头的消息路由到payQueue
    @Bean
    public Binding patBinding() {
        return BindingBuilder
                .bind(payQueue())
                .to(payTopicExchange())
                .with("pay.*");
    }

    //绑定2 所有支付相关的消息（路由建包含 ”pay“）路由到payLogQueue
    @Bean
    public Binding payLogBinding() {
        return BindingBuilder
                .bind(payLogQueue())
                .to(payTopicExchange())
                .with("#.pay.#");//匹配任意个pay的单词
    }
}
